from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

url = 'https://imooc.com'
driver = webdriver.Chrome()
driver.get(url)

# element = (driver.find_element(By.CLASS_NAME, 'bg000').
#            find_element(By.TAG_NAME, 'div'))
# elements_a = (element.find_element(By.CLASS_NAME, 'show').
#               find_element(By.TAG_NAME, 'div').
#               find_elements(By.TAG_NAME, 'a'))

elements_a = driver.find_elements(By.XPATH, './/div[@class="bg000"]//div[@data-type="推荐"]/a')
# print(len(elements_a), elements_a)
for index, element in enumerate(elements_a, start=1):
    item = {}
    item['title'] = element.get_attribute('data-title')
    # item['title2'] = element.find_element(By.CLASS_NAME, 'title').text
    item['number'] = element.find_element(By.CLASS_NAME, 'difficulty').text
    item['price'] = element.find_element(By.CLASS_NAME, 'price').text
    item['origin-price'] = element.find_element(By.CLASS_NAME, 'origin-price').text
    print(index, item)


sleep(5)
driver.quit()

